#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<int> printListFromTailToHead(ListNode* head) {

        vector<int> v;

        if (head == nullptr)
        {
            return v;
        }

        ListNode* prev = nullptr;
        ListNode* cur = head;
        ListNode* next = cur->next;


        while (next != nullptr)
        {
            cur->next = prev;
            prev = cur;
            cur = next;
            next = next->next;
        }

        cur->next = prev;


        while (cur != nullptr)
        {
            v.push_back(cur->val);
            cur = cur->next;
        }

        return v;

    }
};